package com.project.server.operate;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.operate.TOperateNotice;
import com.project.server.service.operate.ITOperateNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 通知公告Controller
 *
 * @author project
 * @date 2021-06-29
 */
@RestController
@RequestMapping("/server/notice")
public class TOperateNoticeController extends BaseController {

    @Resource
    private ITOperateNoticeService tOperateNoticeService;

/**
 * 查询通知公告列表
 */
//@PreAuthorize("@ss.hasPermi('server:notice:list')")
@GetMapping("/list")
        public TableDataInfo list(TOperateNotice tOperateNotice) {
        startPage();
        List<TOperateNotice> list = tOperateNoticeService.selectTOperateNoticeList(tOperateNotice);
        return getDataTable(list);
    }

    
    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('server:notice:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TOperateNotice tOperateNotice) {
        List<TOperateNotice> list = tOperateNoticeService.selectTOperateNoticeList(tOperateNotice);
        ExcelUtil<TOperateNotice> util = new ExcelUtil<TOperateNotice>(TOperateNotice. class);
        return util.exportExcel(list, "通知公告列表");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Long noticeId) {
        return AjaxResult.success(tOperateNoticeService.selectTOperateNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('server:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TOperateNotice tOperateNotice) {
        return toAjax(tOperateNoticeService.insertTOperateNotice(tOperateNotice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('server:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TOperateNotice tOperateNotice) {
        return toAjax(tOperateNoticeService.updateTOperateNotice(tOperateNotice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('server:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds) {
        return toAjax(tOperateNoticeService.deleteTOperateNoticeByIds(noticeIds));
    }
}
